package de.mediaScan.scanner;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;

public class InformationReceiver implements Callable<Map<String, String>> {
	private final File file;

	public InformationReceiver(final File file) {
		this.file = file;
	}

	@Override
	public Map<String, String> call() throws Exception {
		final Map<String, String> result = new HashMap<String, String>();

		final AudioFile audio = AudioFileIO.read(this.file);
		final Tag audioTag = audio.getTag();

		result.put("Artist", audioTag.getFirst(FieldKey.ARTIST));
		result.put("Album", audioTag.getFirst(FieldKey.ALBUM));
		result.put("Title", audioTag.getFirst(FieldKey.TITLE));

		return result;
	}
}
